<template>
  <footer class="footer">
    <span class="todo-count"
      ><strong>{{ leftCount }}</strong
      >剩余</span
    >
    <ul class="filters">
      <li>
        <a 
        :class="{selected : type === 'all'}" 
        @click.prevent="$emit('changeType','all')"
        href="#/"
        >全部</a>
      </li>
      <li>
        <a 
        :class="{selected : type === 'active'}" 
        @click.prevent="$emit('changeType','active')"
        href="#/active"
        >进行中</a>
      </li>
      <li>
        <a 
        :class="{selected : type === 'complete'}"  
        @click.prevent="$emit('changeType','complete')"
        href="#/completed"
        >已完成</a>
      </li>
    </ul>
    <button class="clear-completed" @click="clearFn">清除已完成</button>
  </footer>
</template>

<script>
export default {
  props: {
    list: {
      type: Array,
      require: true,
    },
    type:String
  },
  computed: {
    leftCount() {
      return this.list.reduce((sum, item) => {
        if (item.isDone === false) return sum + 1
        return sum
      }, 0)
    },
  },
  methods:{
    clearFn(){
      this.$emit('clear')
    }
  }
}
</script>

<style></style>
